package com.exmaple.lemlin.ui.abstracts;

import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import com.exmaple.lemlin.app.APPIM;
import com.exmaple.lemlin.entity.AccessEvenBus;
import com.exmaple.lemlin.entity.ChatMessage;
import com.exmaple.lemlin.entity.FriendGood;
import com.exmaple.lemlin.manager.ActivityCollector;
import com.exmaple.lemlin.mvp.base.BasePresenter;
import com.exmaple.lemlin.mvp.base.BaseView;
import com.exmaple.lemlin.ui.fragment.AccessSignInFragment;
import com.exmaple.lemlin.ui.fragment.AccessSignUpFragment;
import com.exmaple.lemlin.utils.JsonUtils;
import com.exmaple.lemlin.utils.LogUtils;
import com.exmaple.lemlin.utils.ToastUtil;
import com.trello.rxlifecycle2.LifecycleTransformer;
import com.trello.rxlifecycle2.android.ActivityEvent;
import com.trello.rxlifecycle2.components.support.RxAppCompatActivity;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.jivesoftware.smack.packet.Message;

import java.util.List;

import butterknife.ButterKnife;

public abstract class AbstractBaseActivity<P extends BasePresenter> extends RxAppCompatActivity implements BaseView {

    protected P mPresenter;

    protected abstract int getLayoutId();

    protected abstract void initView();

    protected abstract void initPresenter();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //requestWindowFeature(Window.FEATURE_SWIPE_TO_DISMISS);
        setContentView(getLayoutId());

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Window window = getWindow();
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(Color.TRANSPARENT);
            window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                    | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                        | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
            }
        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            Window window = getWindow();
            window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
                    WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        }

        ButterKnife.bind((this));
        ActivityCollector.addActivity(this);

        EventBus.getDefault().register((this));

        initView();
        initPresenter();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mPresenter != null) {
            mPresenter.detachView();
        }
        ActivityCollector.removeActivity(this);
        EventBus.getDefault().unregister((this));
    }

    @Override
    public void onSuccess() {

    }

    @Override
    public void onHint(String hint) {
        ToastUtil.showShort(APPIM.getContext(), hint);
    }

    @Override
    public <T> LifecycleTransformer<T> bindToLife() {
        return bindUntilEvent(ActivityEvent.STOP);
    }


    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onEventMainThread(AccessEvenBus evenBus) {
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onEventMainThread(ChatMessage message) {

    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onEventMainThread(FriendGood friend) {

    }
}
